#include <algorithm>
#include <iostream>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/compose.hpp>
#include <boost/iostreams/copy.hpp>
#include <alpha/crypto/hash/sha1.hpp>

int main(int argc, char *argv[])
{
	if (argc != 2)
	{
		std::cout << "Usage: sha1sum FILE" << std::endl;
		return 1;
	}
	namespace io = boost::iostreams;
	using alpha::crypto::sha1;
	try
	{
		char digest[sha1::digest_length];
		unsigned char *ptr = (unsigned char *)digest;
		io::copy(io::file_descriptor_source(argv[1]), io::compose(sha1(),
			io::array_sink(digest, digest + sha1::digest_length)));
		std::copy(ptr, ptr + sha1::digest_length,
			std::ostream_iterator<int>(std::cout << std::hex));
		std::cout << " *"<< argv[1] << std::endl;
	}
	catch (...)
	{
		std::cerr << "IO error" << std::endl;
	}
}
